<?php
if( !defined('IN_INDEX') )
{
	posterror("ACCESS DENIED", "This page is hidden.");
	exit;
}

/*******************************************************************
** translate($input)
**	Translates the string based on language file that has been 
**	included.
** RETURN VALUES
**	string - Return a string based on the language in use.
**	string - Returns the same string (default)
*******************************************************************/
function translate($input)
{
	global $LANG;
	if(isset($LANG[$input]))
	{
		return $LANG[$input];
	}
	return $input;
}
/** translate() END **/

/*******************************************************************
** getLangByCountry($input)
**	Determines what language to use based on input country.
** RETURN VALUES
**	string - Return a string on what language to use
**	EN - English (default)
*******************************************************************/
function getLangByCountry($input)
{
	$input = strtoupper($input);
	switch($input)
	{
		case 'NO':
			return 'NO';
			break;
		case 'SE':
			return 'SE';
			break;
		default:
			return 'EN';
			break;
	}
	return 'EN';
}
/** getLangByCountry() END **/

function getCountry()
{
	return 'no';
}
/** getLangByCountry() END **/

/*******************************************************************
** getVisitorCountry($ip)
**	Determines what country the ip is from
** RETURN VALUES
**	"" - Return a empty string (default)
**	string - Returns a string on the country as 2chars, example: US
*******************************************************************/
function getVisitorCountry($ip)
{
	global $db;
	
	$ip_number = sprintf("%u", ip2long($ip));
	$sql = "SELECT * FROM iptoc ".
	"WHERE IP_FROM <= " . $ip_number . " ".
	"AND IP_TO >= " . $ip_number . " ";
		  
	if(!$result = $db->sql_query($sql))
	{
		printError("SQL ERROR", mysql_error($sql) ."<br />" . mysql_errno($sql));
	}
	else
	{
		if($row = $db->sql_fetchrow($result))
		{
			return $row['COUNTRY_CODE2'];
		}
	}
	return "";
}
/** getVisitorCountry() END **/

/*******************************************************************
** get_country_list()
**	Collects a list of countries from the database. Countries 
**	do not get stored twice.
** RETURN VALUES
**	array - Returns an array of countries.
**	- array['country_name'] - fullname of country
**	- array['country_iso'] - 2char representive of country
*******************************************************************/
function get_country_list()
{
	global $db;
	$array = array();
	
	$sql = "SELECT DISTINCT COUNTRY_CODE2, COUNTRY_NAME FROM iptoc";
	if(!$result = $db->sql_query($sql))
	{
		printError("SQL ERROR", mysql_error($sql) ."<br />" . mysql_errno($sql));
	}
	else
	{
		while($row = $db->sql_fetchrow($result))
		{
			if($row['COUNTRY_NAME'] != "")
			{
				$array[] = array(
					'country_name' => $row['COUNTRY_NAME'],
					'country_iso' => $row['COUNTRY_CODE2']
				);
			}
		}
	}

	sort($array);
	return $array;
}
/** get_country_list() END **/

function getCountryName($input)
{
	global $db;
	$iso = strtoupper($input);
	$sql = "SELECT DISTINCT COUNTRY_NAME FROM iptoc ".
	"WHERE COUNTRY_CODE2='" . $iso . "'";
	if(!$result = $db->sql_query($sql))
	{
		printError("SQL ERROR", mysql_error($sql) ."<br />" . mysql_errno($sql));
	}
	else
	{
		if($row = $db->sql_fetchrow($result))
		{
			return $row['COUNTRY_NAME'];
		}
	}
	return "";
}
?>